<?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

include_once("../util/PDOConnectionFactory.class.php");

class CategoriaDAO extends PDOConnectionFactory {

// irá receber uma conexão
    public $conex = null;

    // constructor
    public function __construct() {
        $this->conex = PDOConnectionFactory::getConnection();
    }

    public function Lista($query=null) {
        try {

            if( $query == null ) {
                $query = " SELECT idCategoria, categoria FROM tb_categoria ";
                $stmt = $this->conex->query($query);
            }else {
                $stmt = $this->conex->query($query);
            }
            // desconecta
            $this->conex = null;
            // retorna o resultado da query
            return $stmt;
        }catch( PDOException $ex ) {
            echo "Erro: ".$ex->getMessage();
        }
    }

    
    public function saveContaCategoria($contaCategoria ) {
        try {
            $this->conex = PDOConnectionFactory::getConnection();
            $stmt = $this->conex->prepare("INSERT INTO tb_conta_categoria (idConta, idCategoria) VALUES (?,?)");
            $stmt->bindValue(1, $contaCategoria->getIdConta());
            $stmt->bindValue(2, $contaCategoria->getIdCategoria());

            $stmt->execute();

            // fecho a conexão
            $this->conex = null;

        }
        catch ( PDOException $ex  ) {
            echo "Erro: ".$ex->getMessage();
        }
    }
}
?>